package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.DataDetail;
import cn.wolfcode.crm.query.impl.DataDetailQuery;
import cn.wolfcode.crm.service.IDataDetailService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("dataDetail")
public class DataDetailController {
    @Autowired
    IDataDetailService dataDetailService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"dataDetail:view","数据明细页面"},logical= Logical.OR)
    public String view() {
        return "dataDetail";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult getAll(DataDetailQuery dataDetailQuery) {
        return dataDetailService.query(dataDetailQuery);
    }

    @RequestMapping("saveOrUpdate")
    @RequiresPermissions(value = {"dataDetail:save","保存数据明细"},logical= Logical.OR)
    @ResponseBody
    public JSONResult saveOrUpdate(DataDetail dataDetail){
        try {
            dataDetailService.saveOrUpdate(dataDetail);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"列表更新失败");
        }
        return new JSONResult(true,"恭喜您执行成功");
    }
    @RequestMapping("delete")
    @RequiresPermissions(value = {"dataDetail:change","修改数据明细状态"},logical= Logical.OR)
    @ResponseBody
    public JSONResult delete(Long id){
        try {
            dataDetailService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"状态更新失败");
        }
        return new JSONResult(true,"状态更新成功");
    }
    @RequestMapping("menu")
    @ResponseBody
    public List<DataDetail> selectAllByCus(String sn){
        List<DataDetail> dataDetails = dataDetailService.selectAllByCus(sn);
        return dataDetails;
    }
}
